package com.sky.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.sky.dto.ProposalDTO;
import com.sky.dto.WxLoginDTO;
import com.sky.dto.WxPhoneDTO;
import com.sky.entity.Proposal;
import com.sky.entity.WxUser;
import com.sky.properties.JwtProperties;
import com.sky.result.Result;
import com.sky.service.WxUserService;
import com.sky.utils.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/user")
@Slf4j
public class WxUserController {

    @Value("${sky.wechat.appid}")
    private String appid;

    @Value("${sky.wechat.secret}")
    private String secret;

    @Autowired
    private WxUserService wxUserService;
    
    @Autowired
    private RestTemplate restTemplate;
    
    @Autowired
    private JwtProperties jwtProperties;

    @PostMapping("/wxLogin")
    public Result<Object> wxLogin(@RequestBody WxLoginDTO wxLoginDTO) {
        log.info("微信用户登录：{}", wxLoginDTO);
        return wxUserService.wxLogin(wxLoginDTO);
    }

    @PostMapping("/bindPhone")
    public Result<Object> bindPhone(@RequestBody WxPhoneDTO wxPhoneDTO, @RequestHeader("token") String token) {
        log.info("绑定手机号：{}", wxPhoneDTO);
        return wxUserService.bindPhone(wxPhoneDTO, token);
    }

    /**
     * 提交用户反馈
     * @param proposalDTO 反馈信息
     * @return Result
     */
    @PostMapping("/proposal")
    public Result<String> submitProposal(@RequestBody ProposalDTO proposalDTO) {
        log.info("收到用户反馈：{}", proposalDTO);
        return wxUserService.submitProposal(proposalDTO);
    }

    @GetMapping("/proposal/list")
    public Result<List<Proposal>> getProposalList() {
        return wxUserService.getProposalList();
    }

    @DeleteMapping("/proposal/{id}")
    public Result<String> deleteProposal(@PathVariable Long id) {
        return wxUserService.deleteProposal(id);
    }
}